package com.cy.detectsys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cy.detectsys.config.CustomException;
import com.cy.detectsys.entity.*;
import com.cy.detectsys.mapper.MinioFileMapper;
import com.cy.detectsys.service.*;
import com.cy.detectsys.util.R;
import com.cy.detectsys.util.TaskIdGenerator;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

import static com.cy.detectsys.util.FileOperateUtil.moveFile;
import static com.cy.detectsys.util.ZipUtil.zipFolder;

/**
 *  处理【探针脚本】相关的接口
 */

@RestController
@Slf4j
@RequestMapping("probe")
public class ProbeController {



    @Resource
    private TaskIdGenerator taskIdGenerator;

    @Resource
    private ProbenodeResourceService probenodeResourceService;

    @Resource
    private TcPackageService tcPackageService;

    @Resource
    private TcTaskService tcTaskService;


    @Resource
    private MinioFileMapper minioFileMapper;


    @Resource
    private ProbeResourceService resourceService;

    @RequestMapping("list")
    @Transactional
    public R list(){

        List<ProbeResource> list = resourceService.list();
        return R.ok(list);

    }

    @RequestMapping("query/list/level")
    public R queryProbeIdList(@RequestParam Integer level){

        if (level == null) {
            throw new CustomException("任务阶段level 未提交");
        }
        QueryWrapper<ProbeResource> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("level", level);
        List<ProbeResource> list = resourceService.list(queryWrapper);
        List<Integer> collect = list.stream().map(item -> item.getId()).collect(Collectors.toList());
        return R.ok(collect);

    }


}
